package com.frame.work.config;

import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @author wjming
 * @ClassName: RabbitConfig
 * @Description: 建交换机, 队列, 并建立关系
 * @Date 2021/2/22 15:17
 */
@Configuration
public class RabbitConfig {
//    @Value("${directExchange}")
//    private String directExchange;

    @Value("${topic.rabbit.gatewayWriteChannel}")
    private String gatewayWriteChannel;

    @Value("${topic.rabbit.smartHomeFrameProcess}")
    private String smartHomeFrameProcess;

    @Value("${topic.rabbit.userAddTransferHomeMessage}")
    private String userAddTransferHomeMessage;

    /**
     * 通用队列处理
     */
    @Value("${topic.rabbit.generalQueueProcessing}")
    private String generalQueueProcessingValue;

    /**
     * 删除延时时间
     */
    @Value("${topic.rabbit.deviceDelayTime}")
    private String deviceDelayTime;

    /**
     * 删除群组中的设备
     */
    @Value("${topic.rabbit.deviceRemoveGroup}")
    private String deviceRemoveGroup;

    @Value("${topic.rabbit.userReqCount}")
    private String userReqCount;

    @Value("${topic.rabbit.userLoginMessage}")
    private String userLoginMessage;

    @Value("${topic.ttl}")
    private Integer ttl;

//    @Bean
//    public DirectExchange directExchange() {
//        return new DirectExchange(directExchange);
//    }

    @Bean
    public Queue queueGatewayWrites() {
        Map<String, Object> arguments = new HashMap<>(1);
        arguments.put("x-message-ttl", ttl);
        return new Queue(gatewayWriteChannel, true, false, false, arguments);
    }

    @Bean
    public Queue smartHomeFrameProcesss() {
        Map<String, Object> arguments = new HashMap<>(1);
        arguments.put("x-message-ttl", ttl);
        return new Queue(smartHomeFrameProcess, true, false, false, arguments);
    }

    @Bean
    public Queue userAddTransferHomeMessages() {
        Map<String, Object> arguments = new HashMap<>(1);
        arguments.put("x-message-ttl", ttl);
        return new Queue(userAddTransferHomeMessage, true, false, false, arguments);
    }

    @Bean
    public Queue generalQueueProcessingValues() {
        Map<String, Object> arguments = new HashMap<>(1);
        arguments.put("x-message-ttl", ttl);
        return new Queue(generalQueueProcessingValue, true, false, false, arguments);
    }

    @Bean
    public Queue deviceDelayTimes() {
        Map<String, Object> arguments = new HashMap<>(1);
        arguments.put("x-message-ttl", ttl);
        return new Queue(deviceDelayTime, true, false, false, arguments);
    }

    @Bean
    public Queue deviceRemoveGroups() {
        Map<String, Object> arguments = new HashMap<>(1);
        arguments.put("x-message-ttl", ttl);
        return new Queue(deviceRemoveGroup, true, false, false, arguments);
    }

    @Bean
    public Queue userReqCount() {
        Map<String, Object> arguments = new HashMap<>(1);
        arguments.put("x-message-ttl", 60);
        return new Queue(userReqCount, true, false, false, arguments);
    }

    @Bean
    public Queue userLoginMessage() {
        Map<String, Object> arguments = new HashMap<>(1);
        arguments.put("x-message-ttl", 60);
        return new Queue(userLoginMessage, true, false, false, arguments);
    }

//    @Bean
//    public Binding bindingDirectExchange1(Queue gatewayWriteChannel, DirectExchange directExchange) {
//        return BindingBuilder.bind(gatewayWriteChannel).to(directExchange).with("routingKey1");
//    }
//
//    @Bean
//    public Binding bindingDirectExchange2(Queue smartHomeFrameProcess, DirectExchange directExchange) {
//        return BindingBuilder.bind(smartHomeFrameProcess).to(directExchange).with("routingKey2");
//    }
}
